home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / pfmh5.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  12KB  |  387 lines

  1.  /********************************************************
  2.  *                                                       *
  3.  *            PROCESS FMH-5                              *
  4.  *                                                       *
  5.  * This procedure handles the processing of the          *
  6.  * the FMH-5 record (Attach).                            *
  7.  *                                                       *
  8.  * INPUT : the FMHCOM record                             *
  9.  *                                                       *
  10.  * OUTPUT: if error : build the fmh-7 and send it, or    *
  11.  *                    close the session.                 *
  12.  *         if no error: call appl. program (pointer to   *
  13.  *                      wich was set in the ATTACH_LU    *
  14.  *                      record.                          *
  15.  *                                                       *
  16.  *                                                       *
  17.  * CopyRight 1995. Nicholas Poljakov all rights reserved.*
  18.  *                                                       *
  19.  ********************************************************/
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <malloc.h>
  23. #include <signal.h>
  24. #include <fcntl.h>
  25. #include <fmh5.h>
  26. #include <fmh7.h>
  27. #include <fmhcom.h>
  28. #include <prefix.h>
  29. #include <rcb.h>
  30. #include <tcb.h>
  31. #include <lucb.h>
  32. #include <drcb.h>
  33. #include <rcbd.h>
  34. #include <crtp.h>
  35. #include <state1.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <string.h>
  39.  
  40. int tpst_pid;
  41. int tpst_fd[2];
  42. int got_sig;
  43. int semid;
  44. struct lucb lu6;
  45. unsigned long upmex(void *, void *);
  46. unsigned long calltpn(void *, void *);
  47. unsigned long rmfmh5(void *, void *);
  48. int bldfmh7(struct rcb *, unsigned long);
  49. int psrm(int, void *, void *);
  50. int proterr(struct rcb *, unsigned long);
  51. int dcp(struct tcb *);
  52. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  53. int sendhsf(void *);
  54.  
  55. pfmh5(s_ptr)
  56. char *s_ptr;
  57. {
  58.     unsigned int code;
  59.     unsigned long sense;
  60.     struct cma { /* RM fills this structure */
  61.                  struct tcb *p_tcb;
  62.                  struct rcb *p_rcb;
  63.                } ar;
  64.     struct rcb *p_rcb;
  65.     struct tcb *p_tcb;
  66.     struct drcb a_drcb;
  67.     struct rcbd a_rcbd;
  68.  
  69. #if OS_TYPE == 1
  70. /*********  Trace facility **********/
  71. unsigned int rtype;   /* type of record */
  72. unsigned int pnum;    /* point number */
  73. char pname[8];        /* name of module */
  74. char *drec;       /* record for dump */
  75. int  lenr;            /* record length */
  76.  
  77. rtype = INPROC;
  78. strcpy(pname, "pfmh5");
  79. pnum = 1;
  80. drec = s_ptr;
  81. lenr = 200;
  82. gtf(rtype, pname, pnum, drec, lenr);
  83. /***********************************/
  84. #endif
  85.  
  86.     sense = rmfmh5(s_ptr, &ar); /* Call RM for check header*/
  87.     switch (sense) {
  88.         case 0x00000000 :
  89.                           { /* Load and call TP */
  90.                             sense = upmex(s_ptr, &ar);
  91.                             if (sense == 0) {
  92.                 return 0;
  93.                             }
  94.                             p_rcb = ar.p_rcb;
  95.                             bldfmh7(p_rcb, sense);
  96.                           /* Deallocate RCB */
  97.                             p_tcb = ar.p_tcb;
  98.                             a_drcb.p_tcb = p_tcb;
  99.                             a_drcb.p_rcb = p_rcb;
  100.                             code = DEALLOCATE_RCB;
  101.                             psrm(code, &a_drcb, &a_rcbd);
  102.                             break;
  103.                           }
  104.         case 0x1008200e :
  105.         case 0x10086000 :
  106.         case 0x10086005 :
  107.         case 0x10086009 :
  108.         case 0x10086011 :
  109.         case 0x10086040 :
  110.                           { /* deactivate session */
  111.                             p_rcb = ar.p_rcb;
  112.                             if (p_rcb == NULL) {
  113.                                 break;
  114.                             }
  115.                             proterr(p_rcb, sense);
  116.                 dcp(p_tcb);
  117.                             break;
  118.                           }
  119.         default:
  120.                           {
  121.                             p_rcb = ar.p_rcb;
  122.                             if (p_rcb != NULL) {
  123.                                 bldfmh7(p_rcb, sense);
  124.                               /* Deallocate RCB */
  125.                                 p_tcb = ar.p_tcb;
  126.                                 a_drcb.p_tcb = p_tcb;
  127.                                 a_drcb.p_rcb = p_rcb;
  128.                                 code = DEALLOCATE_RCB;
  129.                                 psrm(code, &a_drcb, &a_rcbd);
  130.                             }
  131.                             break;
  132.                           }
  133.  
  134.      }
  135. }
  136. unsigned long upmex(s_ptr, ar)
  137. char *s_ptr;
  138. struct cma { /* RM fills this structure */
  139.              struct tcb *p_tcb;
  140.              struct rcb *p_rcb;
  141.            } *ar;
  142. /*
  143.  * Call the user defined subroutine as a trans. prog.
  144.  */
  145. {
  146.     struct FMH5 *p_fmh5;
  147.     struct crtp *p_crtp;
  148.     struct lucb *p_lucb;
  149.     struct tcb *p_tcb;
  150.     struct rcb *p_rcb;
  151.     struct fmhcom *p_fmh;
  152.     struct LUOW1 *p_luow;
  153.     char *p;
  154.     int i;
  155.     unsigned char cnt;
  156.     unsigned long sense;
  157.  
  158.     p_fmh = (struct fmhcom *)s_ptr;
  159.     p_fmh5 = (struct FMH5 *)(p_fmh -> ru);
  160.     p_luow = (struct LUOW1 *)&((*p_fmh5).tpname);
  161.     cnt = p_fmh5 -> lntpn;
  162.     p_luow = (char *)p_luow + cnt;
  163.  
  164.     p_tcb = ar -> p_tcb;
  165.     p_rcb = ar -> p_rcb;
  166.     p_lucb = p_tcb -> p_lucb;
  167.  
  168.     if ((p_crtp = calloc(1, sizeof(struct crtp))) == NULL) {
  169.         sense = 0x084b6031; /* trans_pgm_not_avail_retry */
  170.         return(sense);
  171.     }
  172.     /*
  173.      * Initialisation the CREATE_TP record
  174.      */
  175.     p_crtp -> code = 0x2300;
  176.     p_crtp -> sense = 0;
  177. #if OS_TYPE == 1
  178.     p_crtp -> rsrv4.semid = semid;
  179. #endif
  180.     memcpy(p_crtp -> tp_id, p_tcb -> tcb_id, 8);
  181.     memcpy(p_crtp -> lu_id, p_lucb -> lu_id, 8);
  182.     p_crtp -> conv_id = p_rcb -> rcb_id;
  183.     p_crtp -> type = 0; /* Basic */
  184.     p_crtp -> sync_level = 0; /* None */
  185.     memcpy(p_crtp -> mode_name, p_rcb -> mode_name, 8);
  186.     memcpy(p_crtp -> partner, p_rcb -> lu_name, 8);
  187.     if (p_luow -> lnluw != 0) {
  188.         p = &((*p_luow).fqnam);
  189.         cnt = p_luow -> lnfqn;
  190.         memcpy(p_crtp -> flun, p, cnt);
  191.         p_crtp -> flun_lt = cnt;
  192.     }
  193.  
  194.     cnt = p_fmh5 -> lntpn;
  195.     memset(p_crtp -> tp_name, 0, 64);
  196.     p = &((*p_fmh5).tpname);
  197.     memcpy(p_crtp -> tp_name, p, cnt);
  198.     strcpy(p_crtp -> rsrv1, lu6.lu_name);
  199.     for (i = 7; i > 0; i--) {
  200.         if ((p_crtp -> rsrv1[i] == 0)||(p_crtp -> rsrv1[i] == 32)) {
  201.             p_crtp -> rsrv1[i] = 0x0;
  202.         }
  203.     }
  204.     sense = calltpn(p_crtp, p_tcb);
  205.     return(sense);
  206. }
  207. /*
  208.  * Build the function management header type 7.
  209.  * 1) Purge an output queue;
  210.  * 2) Built the FMH-7 and insert it into the output queue;
  211.  * 3) Call Sendhs to flush output queue and send the FMH-5.
  212.  */
  213. int bldfmh7(p_rcb, sense)
  214. struct rcb *p_rcb;
  215. unsigned long sense;
  216. {
  217.     struct FMH7 *p_fmh7;
  218.     struct prefix *p_prf;
  219.     char *p;
  220.     char p1;
  221.     unsigned int type;
  222.     unsigned char lt;
  223.  
  224.     lt = sizeof(struct FMH7);
  225.     p_fmh7 = malloc(lt);
  226.     p_fmh7 -> length = lt;
  227.     p_fmh7 -> type = 7;
  228.     memcpy(p_fmh7 -> sense, &sense, 4);
  229. #if OS_TYPE == 0 /* MS-DOS */
  230.     p1 = p_fmh7 -> sense[0];
  231.     p_fmh7 -> sense[0] = p_fmh7 -> sense[3];
  232.     p_fmh7 -> sense[3] = p1;
  233.     p1 = p_fmh7 -> sense[1];
  234.     p_fmh7 -> sense[1] = p_fmh7 -> sense[2];
  235.     p_fmh7 -> sense[2] = p1;
  236. #endif
  237.     p_fmh7 -> nfld = 0;
  238. /*
  239.  * Purge the output and input queues.
  240.  */
  241.     p = (char *)(p_rcb -> first_out);
  242.     p1 = 'D';
  243.     p_prf = p_rcb -> first_out;
  244.     while (p_prf != NULL) {
  245.         buffmng(p1, p_prf, p, p_rcb,0,0,0); /* Delete buff. */
  246.         p_prf = p_prf -> next;
  247.     }
  248.     p = (char *)(p_rcb -> first_in);
  249.     p1 = 'D';
  250.     p_prf = p_rcb -> first_in;
  251.     while (p_prf != NULL) {
  252.         buffmng(p1, p_prf, p, p_rcb,0,0,0); /* Delete buff. */
  253.         p_prf = p_prf -> next;
  254.     }
  255. /*
  256.  * Place the FMH-7 in output queue.
  257.  */
  258.     p = (char *)(p_rcb -> first_out);
  259.     p1 = 'A';
  260.     type = Fmh;
  261.     buffmng(p1, p_fmh7, p, p_rcb, lt, 0, type);
  262.  
  263.     sendhsf(p_rcb); /* Flush output queue */
  264. }
  265. #if OS_TYPE == 1
  266. unsigned long calltpn(p, p_tcb)
  267. struct crtp *p;
  268. struct tcb *p_tcb;
  269. {
  270.     struct rsp {
  271.                   int long unsigned sense;
  272.                   int tp_pid;
  273.                } rs;
  274.     char p1[40];
  275.     char p2[6];
  276.     char buff[7];
  277.     int i;
  278.     int cnt;
  279.     int *j;
  280.     int lu_pid;
  281.     int short resp;
  282.     int flags;
  283. /*********  Trace facility **********/
  284. unsigned int rtype;   /* type of record */
  285. unsigned int pnum;    /* point number */
  286. char pname[8];        /* name of module */
  287. char *drec;       /* record for dump */
  288. int  lenr;            /* record length */
  289.  
  290. rtype = INPROC;
  291. strcpy(pname, "calltpn");
  292. pnum = 1;
  293. drec = p;
  294. lenr = sizeof(struct crtp);
  295. gtf(rtype, pname, pnum, drec, lenr);
  296. /***********************************/
  297.  
  298.     if ((cnt = write(tpst_fd[1], p, sizeof(struct crtp))) < 0) {
  299.         return (0x084c0000); /* tp not available no retry */
  300.     }
  301. printf("LUPS...calltpn WRITE O.K!...cnt = %d\n",cnt);
  302.     kill(tpst_pid, SIGUSR1);
  303.     while (got_sig == 0);  /* Wait for signal from TPST */
  304.     got_sig--;
  305.     if ((cnt = read(tpst_fd[0], &rs, sizeof(struct rsp))) < 0) {
  306.         return (0x084c0000); /* tp not available no retry */
  307.     }
  308. printf("LUPS...calltpn READ O.K!...cnt = %d\n",cnt);
  309.  
  310. /***********************************/
  311. rtype = GREC;
  312. strcpy(pname, "calltpn");
  313. pnum = 2;
  314. drec = &rs;
  315. lenr = sizeof(struct rsp);
  316. gtf(rtype, pname, pnum, drec, lenr);
  317. /***********************************/
  318.  
  319.     if (rs.sense == OK) {
  320.         strcpy(p1, PPATH);
  321.         strcat(p1, "tp");
  322.         sprintf(p2, "%d", rs.tp_pid);
  323.         strcat(p1, p2);
  324.         mknod(p1, IFIFO|0666, 0);
  325.         if ((p_tcb -> tp_fd = open(p1, O_RDWR | O_NDELAY)) < 0) {
  326.             rs.sense = 0x084c0000; /* tp not available no retry */
  327.             kill(rs.tp_pid, SIGKILL);
  328.             return(rs.sense);
  329.         }
  330. printf("LUPS...calltpn...fifo to TP now is open...\n");
  331.         if ((flags=fcntl(p_tcb -> tp_fd,F_GETFL,0))== -1)  {
  332.             rs.sense = 0x084c0000; /* tp not available no retry */
  333.             kill(rs.tp_pid, SIGKILL);
  334.             close(p_tcb -> tp_fd);
  335.             return(rs.sense);
  336.         }
  337.         if (fcntl(p_tcb -> tp_fd,F_SETFL,flags & ( 0xffff - O_NDELAY) ) == -1) {
  338.             rs.sense = 0x084c0000; /* tp not available no retry */
  339.             kill(rs.tp_pid, SIGKILL);
  340.             close(p_tcb -> tp_fd);
  341.             return(rs.sense);
  342.         }
  343.         /* Read response from TP */
  344.         if ((cnt = read(p_tcb -> tp_fd, &resp, sizeof(short))) < 0) {
  345.             rs.sense = 0x084c0000; /* tp not available no retry */
  346.             kill(rs.tp_pid, SIGKILL);
  347.             close(p_tcb -> tp_fd);
  348.             return(rs.sense);
  349.         }
  350. printf("LUPS...calltpn...response from TP was received...\n");
  351.         flags = O_WRONLY & (0xffff - O_NDELAY);
  352.         if (fcntl(p_tcb -> tp_fd,F_SETFL,flags) == -1) {
  353.             rs.sense = 0x084c0000; /* tp not available no retry */
  354.             kill(rs.tp_pid, SIGKILL);
  355.             close(p_tcb -> tp_fd);
  356.             return(rs.sense);
  357.         }
  358.         /* Write to TP create_TP record */
  359.         if ((cnt = write(p_tcb -> tp_fd, p, sizeof(struct crtp))) < 0) {
  360.             rs.sense = 0x084c0000; /* tp not available no retry */
  361.             kill(rs.tp_pid, SIGKILL);
  362.             close(p_tcb -> tp_fd);
  363.             return(rs.sense);
  364.         }
  365. printf("LUPS...calltpn...write to TP O.K! cnt = %d\n", cnt);
  366.  
  367.         /* Set tp_id */
  368.         p_tcb -> tp_pid = rs.tp_pid;
  369.     }
  370.  
  371.     return(rs.sense);
  372. }
  373. handler()
  374.         {
  375.             got_sig++;
  376.             return 0;
  377.         }
  378. #endif
  379. #if DEBUG == 1
  380. unsigned long calltpn(p, p_tcb)
  381. struct crtp *p;
  382. struct tcb *p_tcb;
  383. {
  384.     return (0);
  385. }
  386. #endif
  387.